import React, {Component} from 'react';
import {Form, Button, Input, Space} from 'antd'
import {filtering} from "@/utils/regexp";

class Editor extends Component {
    componentDidMount() {
        const {dataSource} = this.props
        if (dataSource) {
            this.formRef.setFieldsValue({storeServiceName: dataSource.storeServiceName})
        }
    }

    render() {
        const {onFinish, dialogClose, btnLoading} = this.props
        return <Form onFinish={onFinish} ref={ref => this.formRef = ref}>
            <Form.Item label={'名称'}
                       rules={[{required: true}, {max: 10}, {pattern: filtering, message: '名称不允许输入特殊字符或空格'}]}
                       name={'storeServiceName'}>
                <Input maxLength={10}/>
            </Form.Item>
            <div style={{display: 'flex', justifyContent: 'flex-end'}}>
                <Space>
                    <Button onClick={dialogClose}>取消</Button>
                    <Button loading={btnLoading} type="primary" htmlType="submit">确认</Button>
                </Space>
            </div>
        </Form>
    }
}

export default Editor;